﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace BYManageInfoSystem
{
    public partial class Frm_FacFeeRelation : Form
    {
        private int m_nSelectFacFeeRelationTabID = 0;
        private int m_nSelectFacFeeTabID = 0;
        private string m_strFeeCate = "";
        private string m_strContract = "";
        private DGBY.BLL.FacFeeRelationTab m_bllFacFeeRelationTab = new DGBY.BLL.FacFeeRelationTab();
    
        public Frm_FacFeeRelation()
        {
            InitializeComponent();
        }
        public Frm_FacFeeRelation(int nSelectFacFeeTabID, string strFeeCate, string strContract)
        {
            m_nSelectFacFeeTabID = nSelectFacFeeTabID;
            m_strFeeCate = strFeeCate;
            m_strContract = strContract;
            InitializeComponent();
        }
        public Frm_FacFeeRelation(int nSelectFacFeeTabID, string strFeeCate)
        {
            m_nSelectFacFeeTabID = nSelectFacFeeTabID;
            m_strFeeCate = strFeeCate;
            InitializeComponent();
        }
        private void ShowFacFeeInfoByID(int nSelectFacFeeTabID, string strFeeCate)
        {
            DataSet ds = m_bllFacFeeRelationTab.GetFeeNameList("FacFeeTabID = " + nSelectFacFeeTabID.ToString() + " and FeeCateTab.FeeCateName like " + "'%" + strFeeCate + "%'");
            if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                dataGridViewCargoBoxInfo.DataSource = ds.Tables[0];
                dataGridViewCargoBoxInfo.Columns[0].Visible = false;
                dataGridViewCargoBoxInfo.Columns[1].Visible = false;
            }
        }
        private void Frm_FacFeeRelation_Load(object sender, EventArgs e)
        {
            ShowFacFeeInfoByID(m_nSelectFacFeeTabID, m_strFeeCate);
            this.Text = "合同号" + m_strContract;
        }

        private void buttonMod_Click(object sender, EventArgs e)
        {
            try
            {
                if (ClassInputValid.IsDecimal(this.errorProvider1, this.textBoxJinE))
                    return;
                DGBY.Model.FacFeeRelationTab modelFacFeeRelationTab = m_bllFacFeeRelationTab.GetModel(m_nSelectFacFeeRelationTabID);
                if (modelFacFeeRelationTab == null)
                {
                    MessageBox.Show("数据库不存在该记录!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }


                modelFacFeeRelationTab.FeeMoney = Convert.ToDecimal(this.textBoxJinE.Text);

                m_bllFacFeeRelationTab.Update(modelFacFeeRelationTab);
                ShowFacFeeInfoByID(m_nSelectFacFeeTabID, m_strFeeCate);
                MessageBox.Show("数据修改成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

            }
           
        }

        private void dataGridViewCargoBoxInfo_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            string strFacFeeRelationTabID = this.dataGridViewCargoBoxInfo.Rows[this.dataGridViewCargoBoxInfo.CurrentCell.RowIndex].Cells[0].Value.ToString();
            m_nSelectFacFeeRelationTabID = Convert.ToInt32(strFacFeeRelationTabID, 10);
            this.textBoxFeeName.Text = this.dataGridViewCargoBoxInfo.Rows[this.dataGridViewCargoBoxInfo.CurrentCell.RowIndex].Cells[2].Value.ToString();
            this.textBoxJinE.Text = this.dataGridViewCargoBoxInfo.Rows[this.dataGridViewCargoBoxInfo.CurrentCell.RowIndex].Cells[3].Value.ToString();
        }

        private void dataGridViewCargoBoxInfo_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
        {
            {
                using (SolidBrush b = new SolidBrush(dataGridViewCargoBoxInfo.RowHeadersDefaultCellStyle.ForeColor))
                {
                    e.Graphics.DrawString((e.RowIndex + 1).ToString(System.Globalization.CultureInfo.CurrentUICulture), e.InheritedRowStyle.Font, b, e.RowBounds.Location.X + 10, e.RowBounds.Location.Y + 4);
                }
            }
        }
    }
}
